package com.sky.controller.admin;

import com.alibaba.fastjson.JSON;
import com.sky.dto.User;
import com.sky.entity.EmployeeEntity;
import com.sky.enumeration.UserStatus;
import com.sky.mapper.EmployeeMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@Slf4j
public class TestController {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Value("${env}")
    private String env;

    @GetMapping("/test")
    public Object test() {
//        User user = new User();
//        user.setStatus(UserStatus.Faild);
//        System.out.println(user);
//        String jsonString = JSON.toJSONString(user);
//        System.out.println(jsonString);
//        User jsonObject = JSON.parseObject(jsonString,User.class);
//        System.out.println(jsonObject);
//        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
//        objectObjectHashMap.put("user",user);
//        objectObjectHashMap.put("string",jsonString);
//        objectObjectHashMap.put("obj",jsonObject);
//
//        System.out.println(JSON.toJSONString(UserStatus.Faild));
//        System.out.println(String.format("运行环境%s",env));
//        return objectObjectHashMap;
        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("123", "12312");

        return objectObjectHashMap;
    }

    @GetMapping("/test_sql")
    public EmployeeEntity testSql() {
        EmployeeEntity select = employeeMapper.select();
        return select;
    }

    @PostMapping("/test_form_post")
    public String TestFormPost(@RequestParam("id") Integer id, @RequestParam("name") String name) {
        log.info("入参数据 {} {}", id, name);
        StringBuilder stringBuilder = new StringBuilder();
        String string = stringBuilder.append("测试完成 -- ").append(id + "--").append(name).toString();
        return string;
    }

}
